//
//  MyInforLookerWeiMaViewController.m
//  LovingPartyBuilding
//
//  Created by 刘应平 on 17/5/4.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "MyInforLookerWeiMaViewController.h"
#import <CoreImage/CoreImage.h>
@interface MyInforLookerWeiMaViewController ()
/**  二维码图片  */
@property (strong, nonatomic) UIImageView  *imageView;
/**  头像  */
@property (strong, nonatomic) UIImageView  *headImageView;
/**  名字  */
@property (strong, nonatomic) UILabel  *nameLabel;

@end

@implementation MyInforLookerWeiMaViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.titlelabel.text = @"我的二维码";
    self.view.backgroundColor = [UIColor themeGrayColor];
    [self.view addSubview:self.imageView];
    [self creatCIQRCodeImage];
    
    
    [self.view addSubview:self.headImageView];
    [self.view addSubview:self.nameLabel];
    
    self.headImageView.sd_layout
    .topSpaceToView(self.view,navHeight + 40 * [UIScreen zj_screenHScale])
    .leftSpaceToView(self.view,30 * [UIScreen zj_screenWScale])
    .heightIs(60 * [UIScreen zj_screenHScale])
    .widthIs(60 * [UIScreen zj_screenHScale]);
    
    self.nameLabel.sd_layout
    .leftSpaceToView(self.headImageView,10 * [UIScreen zj_screenWScale])
    .topSpaceToView(self.view,navHeight + 60 * [UIScreen zj_screenHScale])
    .heightIs(20 * [UIScreen zj_screenHScale])
    .widthIs(100 * [UIScreen zj_screenWScale]);
}

/**
 *  生成二维码
 */
- (void)creatCIQRCodeImage
{
    // 1.创建过滤器，这里的@"CIQRCodeGenerator"是固定的
    CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
    
    // 2.恢复默认设置
    [filter setDefaults];
    
    // 3. 给过滤器添加数据
    NSString *dataString = ZJUSERINFORMODEL.ORG_ACCOUNT.CODE_URL;
    NSData *data = [dataString dataUsingEncoding:NSUTF8StringEncoding];
    // 注意，这里的value必须是NSData类型
    [filter setValue:data forKeyPath:@"inputMessage"];
    
    // 4. 生成二维码
    CIImage *outputImage = [filter outputImage];
    
    // 5. 显示二维码
    self.imageView.image = [UIImage creatNonInterpolatedUIImageFormCIImage:outputImage withSize:180];
}

- (void)action_leftButton:(UIButton *)sender{
    if (self.isModel) {
        [self.navigationController dismissViewControllerAnimated:YES completion:nil];
    }else{
        [self.navigationController popViewControllerAnimated:YES];
    }
}

- (UIImageView *)imageView{
    if (!_imageView) {
        _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 180 , 180)];
        _imageView.center = self.view.center;
    }
    return _imageView;

}


- (UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor textBlackColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = [UIFont boldSystemFontOfSize:20 * [UIScreen zj_textFontScale]];
            label.text = ZJUSERINFORMODEL.ORG_ACCOUNT.USER_NAME;
            label;
        });
    }
    return _nameLabel;
}

- (UIImageView *)headImageView{
    if (!_headImageView) {
        _headImageView = [UIImageView new];
        _headImageView.layer.cornerRadius = 30 * [UIScreen zj_screenHScale];
        _headImageView.layer.masksToBounds = YES;
        [_headImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",BASEIMAGEURL,ZJUSERINFORMODEL.ORG_ACCOUNT.PHOTO_URL]] placeholderImage:PlaceholderHeaderImage];
    }
    return _headImageView;
}
@end
